home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1755 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: alterdial.uu.net!not-for-mail
  2. From: Chris Gould <cgould@dataware.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Pointers to multi-D arrays
  5. Date: Fri, 12 Jan 1996 13:28:24 -0500
  6. Organization: Dataware Technologies, Inc.
  7. Message-ID: <30F6A848.602A@dataware.com>
  8. References: <4d4alj$5o8@news.cs.hope.edu>
  9. NNTP-Posting-Host: gw.dataware.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b3 (WinNT; I)
  14.  
  15. Michael Van Opstall wrote:
  16. > How do you make a pointer to a multi dimensional array?
  17. > I have this:
  18. > Complex* data;
  19. > // in the header
  20. > ...
  21. > // the constructor...
  22. > data=new Complex[v][h];
  23. > and I get an error because it's trying to make an array of pointers to
  24. > arrays of Complex instead of one pointer to a larger array.
  25.  
  26. If you want a dynamic pointer to a 2x array you need to use a 
  27. pointer to pointer.  
  28.  
  29. //header
  30. ...
  31.     Complex **data;
  32. ...
  33.  
  34. //constructor
  35. ...
  36. // allocate memory for the 2x array
  37.     data = new Complex *[v];
  38.     for ( i = 0; i < v; i++ ) {
  39.         data[i] = new Complex[h];
  40.     }
  41. ...
  42.